package com.ssyt.wxstore.common.util;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * Alibaba的Fastjson,如果为JAVA Bean,必须有无参构造和getter setter。
 * 
 * @author Hsu。
 * @date 2013-12-2
 */
public class FastjsonUtil {

	private FastjsonUtil() {

	}

	public static <T> List<T> parseArray(String jsonString, Class<T> clazz) {
		return JSON.parseArray(jsonString, clazz);
	}

	public static <T> T parseObject(String jsonString, Class<T> clazz) {
		return JSON.parseObject(jsonString, clazz);
	}

	public static String toJson(Object obj) {
		return JSON.toJSONString(obj);
	}

	public static String toJsonWithDateFormat(Object obj, String dateFormat) {
		return JSON.toJSONStringWithDateFormat(obj, dateFormat,
				SerializerFeature.WriteDateUseDateFormat);
	}
}
